﻿using Microsoft.EntityFrameworkCore;
using Product.EntityFrameworkCore.MapConfiguration;
using Product.EntityFrameworkCore.PO;

namespace Product.EntityFrameworkCore
{
    /// <summary>
    /// EF Core 上下文
    /// </summary>
    public class ProductContext : DbContext, IProductContext
    {
        public ProductContext(DbContextOptions<ProductContext> options)
        : base(options)
        {
            //Database.EnsureCreated();
        }

        override protected void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }

        public DbSet<BrandPo> Brand { get; set; }
        public DbSet<CategoryPo> Category { get; set; }
        public DbSet<SpecificationPo> Specification { get; set; }
        public DbSet<SpuPo> Spu { get; set; }
        public DbSet<UnitPo> Unit { get; set; }
        public DbSet<SkuPo> Sku { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {        
            modelBuilder.ApplyConfiguration(new BrandMapConfiguration());
            modelBuilder.ApplyConfiguration(new CategoryMapConfiguration());
            modelBuilder.ApplyConfiguration(new SkuMapConfiguration());
            modelBuilder.ApplyConfiguration(new SpecificationMapConfiguration());
            modelBuilder.ApplyConfiguration(new SpuMapConfiguration());
            modelBuilder.ApplyConfiguration(new UnitMapConfiguration());

            base.OnModelCreating(modelBuilder);
        }
    }
}
